﻿--[[
   @brief    login view
   @author   jameszhai
   @version  1.0
   @date     2017-05-15
--]]

--[[
SERVICE_BEGIN(Svr_GetLoginRect)
    JSONB(int, screen);     -- 是否屏幕坐标
SERVICE_END

SERVICE_BEGIN(Svr_GetLoginWnd)
    JSONB(int, window);     -- 登录窗口的ID
SERVICE_END

// 静音通知
BROADCAST_BEGIN(Msg_OnLoginMute)
    JSONB(int, mute);       -- 0 -- 未静音  1 -- 静音
BROADCAST_END

// 设置Web静音
BROADCAST_BEGIN(Msg_SetWebMute)
    JSONB(int, mute);       -- 0 -- 未静音  1 -- 静音
BROADCAST_END

// 显示静音按钮
SERVICE_BEGIN(Svr_ShowMuteButton)
    JSONB(int, show);       -- 是否显示: 0 -- 不显示 1 -- 显示
    JSONB(int, mute);       -- 当前状态: 0 -- 未静音    1 -- 静音
SERVICE_END

// 显示TIPS按钮
SERVICE_BEGIN(Svr_ShowToolTips)
    JSONB(string, text);
    JSONB(int, left);
    JSONB(int, top);
SERVICE_END

// 隐藏TIPS
SERVICE_BEGIN(Svr_HideToolTips)
SERVICE_END

--]]

-- 登录类型
ELoginType =
{
    ltQKLogin  = 0;     -- Quick login
    ltSavedAcc = 1;     -- History account login
    ltAccLogin = 2;     -- New account login
    ltQRLogin  = 3;     -- QR login
    ltTEdit    = 4;     -- edit控件登录
    ltMailLogin = 5;    -- 邮箱登录
};

-- 登录界面
ELoginUI = 
{
    -- 布局XML
    sLoginXML   = "login\\cn\\login.tpf";
    sLoginOSXML = "login\\oversea\\login.tpf";

    sUpdateXML  = "login\\Update.xml";
    sLoadingXML = "login\\Loading.xml";
    sQLoginXML  = "login\\QuickLogin.xml";
    sQLoginOSXML = "login\\oversea\\QuickLogin.xml";
    sAddAccXML  = "login\\AddAcc.xml";
    sAddAccOSXML = "login\\oversea\\AddAcc.xml";
    sQRLoginXML = "login\\QRLogin.xml";
    sErrorXML   = "login\\cn\\LoginError.xml";
    sErrorOSXML   = "login\\oversea\\LoginError.xml";
    sPictChkXML = "login\\PictCheck.xml";
    sWeChatQRLoginXML   = "login\\WeChatQRLogin.xml";
    sWeChatQRLoginOSXML = "login\\oversea\\WeChatQRLogin.xml";
    sFaceBookLogin      = "login\\cn\\FaceBookLogin.xml";
    sFaceBookLoginOS    = "login\\oversea\\FaceBookLogin.xml";
    sMailAccXML = "login\\cn\\MailAcc.xml";
    sMailAccOSXML = "login\\oversea\\MailAcc.xml";

    sProxyPrefXML = "login\\ProxyPref.xml";
    -- 界面控件
    sContent    = "pnlMain";
    sObjMain    = "pnlMain\\uoMain";
    sLblTips    = "pnlMain\\lblWGTips"; -- 右下角的广告

    sPnlBack    = "pnlBack";
    sWebBack    = "pnlBack\\Ctn_WebArea\\QBWebBrowser";

    sBtnMin     = "btnMin";
    sBtnCls     = "btnCls";
    sBtnMute    = "pnlMuteContainer\\btnMute";
    sBtnMutePanel    = "pnlMuteContainer";

    sBtnSettings = "btnSettings";
    sBtnMore    = "btnMore";

    sBtnTips    = "btnTips";

    sNavTabPnl  = "pnlMain\\pnlNavigationTab"

};

-- 登录页面
ELoginPage = 
{
    lpMinPage  = 1;
    lpQKLogin  = 1;                     -- 快速登录
    lpAccLogin = 2;                     -- 帐号登录
    lpQRLogin  = 3;                     -- 二维码登录
    lpSecCheck = 4;                     -- 安全检测界面
    lpLogining = 5;                     -- 登录中&安全检测页面
    lpLoginErr = 6;                     -- 登录错误页面
    lpUpdating = 7;                     -- 升级界面
    lpPictChk  = 9;                     -- 验证码
    lpWeChatQRLogin = 10;               -- 微信扫描登录
    lpOverseasLogin     = 11;
    lpMailAccLogin = 12;                -- 邮箱账号登录
    lpProxyPref = 13;                   -- 代理设置

    lpMaxPage  = 14;                    -- 页面不能比这个更大
};

ELoginRes = 
{
    sMuteNrl  = "ONEIMAGE:client_login\\mute_normal.png;Stretch;0";
    sMuteHov  = "ONEIMAGE:client_login\\mute_hover.png;Stretch;0";
    sMuteClk  = "ONEIMAGE:client_login\\mute_press.png;Stretch;0";

    sLauncherBg = "ONEIMAGE:client_login\\launcher_bg.png";

    sSoundNrl = "ONEIMAGE:client_login\\sound_normal.png;Stretch;0";
    sSoundHov = "ONEIMAGE:client_login\\sound_hover.png;Stretch;0";
    sSoundClk = "ONEIMAGE:client_login\\sound_press.png;Stretch;0";
};

TLoginView = 
{
    -- 初始化界面
    InitView = function()
        TLoginView.zPageMap = {};

        -- 子页面XML配置
        if base_utility.CLIENT_TYPE.OVERSEA_VER ==  base_utility.get_client_version_type() then
            TLoginView.zPageMap[ELoginPage.lpOverseasLogin] = ELoginUI.sFaceBookLoginOS;  -- facebook登录
            TLoginView.zPageMap[ELoginPage.lpMailAccLogin] = ELoginUI.sMailAccOSXML;  -- 邮箱登录
            TLoginView.zPageMap[ELoginPage.lpLoginErr] = ELoginUI.sErrorOSXML;      -- 登录错误页面
        else
            TLoginView.zPageMap[ELoginPage.lpOverseasLogin] = ELoginUI.sFaceBookLogin;  -- facebook登录
            TLoginView.zPageMap[ELoginPage.lpMailAccLogin] = ELoginUI.sMailAccXML;  -- 邮箱登录
            TLoginView.zPageMap[ELoginPage.lpLoginErr] = ELoginUI.sErrorXML;        -- 登录错误页面
        end

        TLoginView.zPageMap[ELoginPage.lpWeChatQRLogin] = ELoginUI.sWeChatQRLoginXML;   -- 微信二维码
        TLoginView.zPageMap[ELoginPage.lpQKLogin ] = ELoginUI.sQLoginXML;       -- 快速登录
        TLoginView.zPageMap[ELoginPage.lpAccLogin] = ELoginUI.sAddAccXML;       -- 帐号登录
        TLoginView.zPageMap[ELoginPage.lpQRLogin ] = ELoginUI.sQRLoginXML;      -- 二维码登录
        TLoginView.zPageMap[ELoginPage.lpSecCheck] = ELoginUI.sLoadingXML;      -- 安全检测界面
        TLoginView.zPageMap[ELoginPage.lpLogining] = ELoginUI.sLoadingXML;      -- 登录中&安全检测页面
        TLoginView.zPageMap[ELoginPage.lpUpdating] = ELoginUI.sUpdateXML;       -- 升级界面
        TLoginView.zPageMap[ELoginPage.lpPictChk]  = ELoginUI.sPictChkXML;      -- 验证码
        TLoginView.zPageMap[ELoginPage.lpProxyPref] = ELoginUI.sProxyPrefXML;   -- 代理设置

        -- 加载子页面代码
        ierd_tgp.tpf_ui.Require("wegame_login\\quick_login.lua");
        ierd_tgp.tpf_ui.Require("wegame_login\\login_error.lua");
        ierd_tgp.tpf_ui.Require("wegame_login\\acc_login.lua");
        ierd_tgp.tpf_ui.Require("wegame_login\\loading.lua");
        ierd_tgp.tpf_ui.Require("wegame_login\\login_qr.lua");
        ierd_tgp.tpf_ui.Require("wegame_login\\pict_check.lua");
        ierd_tgp.tpf_ui.Require("wegame_login\\wechat_qrcode.lua");
        ierd_tgp.tpf_ui.Require("wegame_login\\overseas_login.lua");
        ierd_tgp.tpf_ui.Require("wegame_login\\navigation_tab.lua");
        ierd_tgp.tpf_ui.Require("wegame_login\\mail_login.lua");
        ierd_tgp.tpf_ui.Require("wegame_login\\proxy_pref.lua");
        ierd_tgp.tpf_ui.Require("wegame_login\\auth_verify\\control.lua");

        -- 服务定义
        comm_center.reg_service("Svr_GetLoginRect", "TLoginView.OnGetWndRect");
        comm_center.reg_service("Svr_GetLoginWnd", "TLoginView.OnGetLoginWnd");
        comm_center.reg_service("Svr_ShowMuteButton", "TLoginView.OnSvrShowMute");
        comm_center.reg_service("Svr_ShowToolTips", "TLoginView.OnSvrShowTips");
        comm_center.reg_service("Svr_HideToolTips", "TLoginView.OnSvrHideTips");

        comm_center.reg_service("Svr_ShowLoginAd", "TLoginView.ShowLoginAd");

        comm_center.reg_service("Svr_ShowLoginNavTab", "TLoginView.ShowNavTab");
        comm_center.reg_service("Svr_LoginPageGoBack", "TLoginView.GoBackPage");
        comm_center.reg_service("Svr_ShowSettingsButton", "TLoginView.OnSvrShowSettings");
        -- 监听消息
        comm_center.listen_broadcast("Msg_OnLoginMute", "TLoginView.OnMsgWebMute");
    end;

    -- 卸载界面
    UnInitView = function()
        TLoginView.pDlgLogin = nil;
        TLoginView.pObjMain  = nil;

        -- 背景信息
        TLoginView.pPnlBack  = nil;
        TLoginView.pWebBack = nil;
        TLoginView.pBtnMore = nil;

        -- 界面映射表
        TLoginView.zPageMap  = {};          -- ELoginPage <--> PageXML
        TLoginView.nCurPage  = -1;          -- 当前显示的页面索引
        TLoginView.nLstPage  = -1;          -- 最后一个页面
        TGPLog.LogE("LoginV", "TLoginView UnInitView.");
    end;

    -- 初始化一下升级界面，监听升级消息
    InitUpdate = function()
        -- 初始化一下升级界面，监听升级消息
        ierd_tgp.tpf_ui.Require("wegame_login\\update.lua");

        if nil ~= TLoginView.pObjMain then
            TLoginUpdate.InitView(TLoginView.pObjMain:GetControlID());
        else
            TLoginUpdate.InitView(0);
        end;
    end;

    -- 显示界面
    ShowView = function()
        if (not TLoginView.CreateUI()) then
            TGPLog.LogE("LoginV", "Create UI fail.");
            return;
        end;

        if TRUE == TLoginView.pDlgLogin:IsVisible() then
            TLoginView.pDlgLogin:Restore();
        end;

        TLoginView.ShowContent();

        TLoginView.pDlgLogin:Show(TRUE);
        TLoginView.pDlgLogin:BringToTop();

        -- 创建TEDIT
        TLoginModule.CreateTEdit(TLoginView.pDlgLogin:GetHwnd());

        -- 判断窗口位置，如果不在屏幕可见区域，移动到可见位置
        local nScreenCX, nScreenCY = ui_utility.get_screen_resolution();

        if nScreenCX > 0 and nScreenCY > 0 then
            local rtThis = TLoginView.pDlgLogin:GetRectEx(TRUE,TRUE);

            if (rtThis.right <= 0        ) or (rtThis.top <= 0) or
               (rtThis.left  >= nScreenCX) or (rtThis.bottom >= nScreenCY) then
                local nWidth  = rtThis.right  - rtThis.left;
                local nHeight = rtThis.bottom - rtThis.top;

                rtThis.left   = (nScreenCX  - nWidth) / 2;
                rtThis.right  = rtThis.left + nWidth;
                rtThis.top    = (nScreenCY  - nHeight) / 2;
                rtThis.bottom = rtThis.top  + nHeight;
                TLoginView.pDlgLogin:MoveEx(rtThis,TRUE);
            end;
        end;
    end;

    -- 隐藏界面
    HideView = function()
        if (nil ~= TLoginView.pWebBack) then
            TLoginView.pWebBack:Close();
            TLoginView.SetWebMute(false);
            TLoginView.UnloadWebComponent();
        end;

        if nil ~= TLoginView.pDlgLogin then
            TLoginView.HidePage();
            TLoginView.pDlgLogin:Show(FALSE);

            -- 销毁TEDIT
            TLoginModule.DestroyTEdit();
        end;

        TLoginView.pBtnMore = nil;
    end;

    -- 显示右侧部分
    ShowContent = function()
        TLoginView.ShowPage();

        if nil ~= TLoginView.pPnlClient then
            TLoginView.pPnlClient:Show(TRUE);
        else
            TGPLog.LogE("LoginV", "Show content, client is null");
        end;

        if nil ~= TLoginView.pBtnCls then
            TLoginView.pBtnCls:Show(TRUE);
        else
            TGPLog.LogE("LoginV", "Get close button is null");
        end;

        if nil ~= TLoginView.pBtnMin then
            TLoginView.pBtnMin:Show(TRUE);
        else
            TGPLog.LogE("LoginV", "Get min-button is null");
        end;

        if base_utility.is_develop_client() then
            comm_center.call_service("Svr_ShowSettingsButton", { show = 1 });
        end

    end;

    -- 隐藏右侧登录部分
    HideContent = function()
        if nil ~= TLoginView.pPnlClient then
            TLoginView.HidePage();
            TLoginView.pPnlClient:Show(FALSE);
        else
            TGPLog.LogE("LoginV", "Hide content, client is null");
        end;

        if nil ~= TLoginView.pBtnCls then
            TLoginView.pBtnCls:Show(FALSE);
        else
            TGPLog.LogE("LoginV", "Get close button is null");
        end;

        if nil ~= TLoginView.pBtnMin then
            TLoginView.pBtnMin:Show(FALSE);
        else
            TGPLog.LogE("LoginV", "Get min-button is null");
        end;
    end;

    -- 显示页面
    ShowPage = function()
        if     (ELoginPage.lpQKLogin  == TLoginView.nCurPage) then  -- 快速登录
            TQuickLogin.ShowView();
        elseif (ELoginPage.lpAccLogin == TLoginView.nCurPage) then  -- 帐号登录
            TAccLogin.ShowView();
        elseif (ELoginPage.lpQRLogin  == TLoginView.nCurPage) then  -- 二维码登录
            TQRLogin.ShowView();
        elseif (ELoginPage.lpSecCheck == TLoginView.nCurPage) then  -- 安全检测界面
            TLoadingView.ShowView();
        elseif (ELoginPage.lpLogining == TLoginView.nCurPage) then  -- 登录中&安全检测页面
            TLoadingView.ShowView();
        elseif (ELoginPage.lpLoginErr == TLoginView.nCurPage) then  -- 登录错误页面
            TLoginError.ShowView();
        elseif (ELoginPage.lpUpdating == TLoginView.nCurPage) then  -- 升级界面
            TLoginUpdate.ShowView();
        elseif (ELoginPage.lpPictChk  == TLoginView.nCurPage) then  -- 验证码
            TPictCheck.ShowView();
        elseif (ELoginPage.lpWeChatQRLogin == TLoginView.nCurPage) then
            TWeChatQRLogin.ShowView();
        elseif (ELoginPage.lpOverseasLogin == TLoginView.nCurPage) then -- 国际版登陆界面
            TOverseaLogin.ShowView();
        elseif (ELoginPage.lpMailAccLogin == TLoginView.nCurPage) then -- 邮箱登录
            TMailAccLogin.ShowView();
        else
            TGPLog.LogI("LoginV", "Hide page, index error:" .. tostring(TLoginView.nCurPage));
        end;
    end;

    -- 隐藏页面
    HidePage = function()
        if     (ELoginPage.lpQKLogin  == TLoginView.nCurPage) then  -- 快速登录
            TQuickLogin.HideView();
        elseif (ELoginPage.lpAccLogin == TLoginView.nCurPage) then  -- 帐号登录
            TAccLogin.HideView();
        elseif (ELoginPage.lpQRLogin  == TLoginView.nCurPage) then  -- 二维码登录
            TQRLogin.HideView();
        elseif (ELoginPage.lpSecCheck == TLoginView.nCurPage) then  -- 安全检测界面
            TLoadingView.HideView();
        elseif (ELoginPage.lpLogining == TLoginView.nCurPage) then  -- 登录中&安全检测页面
            TLoadingView.HideView();
        elseif (ELoginPage.lpLoginErr == TLoginView.nCurPage) then  -- 登录错误页面
            TLoginError.HideView();
        elseif (ELoginPage.lpUpdating == TLoginView.nCurPage) then  -- 升级界面
            TLoginUpdate.HideView();
        elseif (ELoginPage.lpPictChk  == TLoginView.nCurPage) then  -- 验证码
            TPictCheck.HideView();
        elseif (ELoginPage.lpWeChatQRLogin == TLoginView.nCurPage) then  -- 微信二维码
            TWeChatQRLogin.HideView();
        elseif (ELoginPage.lpOverseasLogin == TLoginView.nCurPage) then -- 国际版登陆界面
            TOverseaLogin.HideView();
        elseif (ELoginPage.lpMailAccLogin == TLoginView.nCurPage) then -- 邮箱登录
            TMailAccLogin.HideView();
        else
            TGPLog.LogE("LoginV", "Hide page, index error:" .. tostring(TLoginView.nCurPage));
        end;
    end;

    -- 创建界面
    CreateUI = function()
        if nil ~= TLoginView.pDlgLogin then
            TGPLog.LogI("LoginV", "UI already created.");
            return true;
        end;
        local layout_xml = ELoginUI.sLoginXML;
        if base_utility.CLIENT_TYPE.OVERSEA_VER ==  base_utility.get_client_version_type() then
            layout_xml = ELoginUI.sLoginOSXML;
        end

        local dwLogin = layout_mgr.restore_layout(layout_xml);

        if not TLoginView.IsInvalid(dwLogin) then
            TGPLog.LogE("LoginV", "Create dialog fail.");
            return false;
        end;
        
        TLoginView.root_id = dwLogin;
        TLoginView.pDlgLogin = ui_utility.get_ctrl_ptr_by_id(dwLogin);

        if (nil == TLoginView.pDlgLogin) then
            TGPLog.LogE("LoginV", "Get login dialog fail.");
            return false;
        end;

        ui_utility.setproperty_by_id(dwLogin, "OnDialogClose", "TLoginView.OnClose");

        TLoginView.pWGADTips = ui_utility.get_ctrl_ptr_by_path(dwLogin, ELoginUI.sLblTips);

        if nil == TLoginView.pWGADTips then
            TGPLog.LogE("LoginV", "Get AD tips fail.");
            return false;
        end;

        TLoginView.pPnlClient = ui_utility.get_ctrl_ptr_by_path(dwLogin, ELoginUI.sContent);

        if nil == TLoginView.pPnlClient then
            TGPLog.LogE("LoginV", "Get content fail.");
            return false;
        end;

        -- User object Main
        TLoginView.pObjMain = ui_utility.get_ctrl_ptr_by_path(dwLogin, ELoginUI.sObjMain);
        TLoginView.pPnlBack = ui_utility.get_ctrl_ptr_by_path(dwLogin, ELoginUI.sPnlBack);
        TLoginView.pNavTab = ui_utility.get_ctrl_ptr_by_path(dwLogin, ELoginUI.sNavTabPnl);

        -- 如果是游戏启动器拉起WeGame需要切换默认背景
        if TLoginCtrl.bIsLauncher then
            ui_utility.setproperty_by_id(TLoginView.pPnlBack:GetControlID(), "Background", ELoginRes.sLauncherBg);
        end;

        if nil == TLoginView.pObjMain or nil == TLoginView.pPnlBack then
            TGPLog.LogE("LoginV", "Background control is null.");
            return false;
        end;


        -- 最小化按钮
        local   btnMin = ui_utility.get_ctrl_id_by_path(dwLogin, ELoginUI.sBtnMin);

        if (TLoginView.IsInvalid(btnMin)) then
            TLoginView.pBtnMin = ui_utility.get_ctrl_ptr_by_id(btnMin);
            ui_utility.setproperty_by_id(btnMin, "OnClick", "TLoginView.OnClkMin");
        else
            TGPLog.LogE("LoginV", "Min control is null.");
            return false;
        end;

        -- 关闭按钮
        local   btnCls = ui_utility.get_ctrl_id_by_path(dwLogin, ELoginUI.sBtnCls);
        if (TLoginView.IsInvalid(btnCls)) then
            TLoginView.pBtnCls = ui_utility.get_ctrl_ptr_by_id(btnCls);
            ui_utility.setproperty_by_id(btnCls, "OnClick", "TLoginView.OnClkCls");
        else
            TGPLog.LogE("LoginV", "Min control is null.");
            return false;
        end;

        TLoginView.pBtnMutePanelID = ui_utility.get_ctrl_id_by_path(dwLogin,ELoginUI.sBtnMutePanel);

        TLoginView.pBtnMute = ui_utility.get_ctrl_ptr_by_path(dwLogin, ELoginUI.sBtnMute);
        TLoginView.pBtnMuteID = ui_utility.get_ctrl_id_by_path(dwLogin, ELoginUI.sBtnMute);

        if nil == TLoginView.pBtnMute then
            TGPLog.LogE("LoginV", "Get mute control fail.");
            return false;
        end;
        ui_utility.setproperty_by_id(TLoginView.pBtnMute:GetControlID(), "OnClick", 
                                     "TLoginView.OnClkMute");
        
        TLoginView.pBtnSetting = ui_utility.get_ctrl_ptr_by_path(dwLogin, ELoginUI.sBtnSettings);
        if nil == TLoginView.pBtnSetting then
            TGPLog.LogE("LoginV", "Get setting control fail.");
            return false;
        end;
        ui_utility.setproperty_by_id(TLoginView.pBtnSetting:GetControlID(), "OnClick", 
                                     "TLoginView.OnClkSetting");

        TLoginView.pBtnMore = ui_utility.get_ctrl_ptr_by_path(dwLogin, ELoginUI.sBtnMore);
        if nil == TLoginView.pBtnMore then
            TGPLog.LogE("LoginV", "Get pBtnMore control fail.");
            return false;
        end;
        ui_utility.setproperty_by_id(TLoginView.pBtnMore:GetControlID(), "OnClick", 
                                     "TLoginView.OnClkMore");
        
        -- ToolTip
        TLoginView.pBtnTips = ui_utility.get_ctrl_ptr_by_path(dwLogin, ELoginUI.sBtnTips);
        if nil == TLoginView.pBtnTips then
            TGPLog.LogE("LoginV", "Get tooltip button fail.");
            return false;
        end;

        ui_utility.setproperty_by_id(dwLogin, "OnShow", "TLoginView.OnWndShow");
        ui_utility.setproperty_by_id(dwLogin, "OnHide", "TLoginView.OnWndHide");
        ui_utility.setproperty_by_id(dwLogin, "OnPosChanged", "TLoginView.OnWndMoved");

        -- 导航栏
        local contentID = ui_utility.get_ctrl_id_by_path(dwLogin, ELoginUI.sContent);
        TNavTabView.InitView(contentID);
        TNavTabView.ShowView(TRUE);

        -- 初始化一下升级界面，监听升级消息
        TLoginView.InitUpdate();
        TLoginView.could_show_navtab = true;
        return true;
    end;

    -- 销毁界面
    DestroyUI = function()
        if nil ~= TLoginView.pDlgLogin then
            TLoginView.UnloadWebComponent();
            TLoginView.pDlgLogin = nil;
        end;
    end;

    -- 窗口显示时处理
    OnWndShow = function()
        -- 解决无法置顶的问题
        local pTPFUI = base_utility.get_component_adapter("ITpf_ui",
                        "ierd_tgp.tpf_ui.GetTPFUI();");

        if nil ~= TLoginView.pDlgLogin and nil ~= pTPFUI then
            local HWND_TOPMOST = pTPFUI:number_to_hwnd(-1);
            local SWP_NOMOVE = 0x002;
            local SWP_NOSIZE = 0x001;

            local dwFlags = SWP_NOMOVE + SWP_NOSIZE;

            --TLoginView.pDlgLogin:SetWindowPos(HWND_TOPMOST, 0, 0, 0, 0, dwFlags);
            TLoginView.pDlgLogin:MoveToCenter();
            TLoginView.pDlgLogin:BringToTop();
        end;
    end;

    -- 窗口隐藏
    OnWndHide = function()
        if TLoginView.hide_by_login_protocal == true then
            return;
        end;
        if nil ~= TLoginView.pDlgLogin then
            TLoginView.HideView();

            local   nDlgID = TLoginView.pDlgLogin:GetControlID();

            ui_utility.end_fake_modal(nDlgID)
            layout_mgr.delay_remove_ctrl(nDlgID);

            TLoginView.pPnlClient= nil;

            TLoginView.pDlgLogin = nil;
            TLoginView.pObjMain  = nil;
            TLoginView.pWGADTips = nil;

            TLoginView.pBtnMute  = nil;     -- 静音按钮
            TLoginView.pBtnCls   = nil;     -- 关闭按钮
            TLoginView.pBtnMin   = nil;     -- 最小化按钮

            TLoginView.pBtnTips  = nil;

            -- 背景信息
            TLoginView.pPnlBack  = nil;     -- 背景
            TLoginView.pWebBack  = nil;     -- 浏览器
        end;
    end;

    OnWndMoved = function()
    end;

    -- 快速登录列表
    SetLoginedList = function(zList)
        if nil ~= TQuickLogin then
            TQuickLogin.SetAccList(zList);
        else
            TGPLog.LogE("LoginV", "Set saved list, quick login module is null.");
        end;
    end;

    -- 历史帐号列表
    SetSavedList = function(zList)
        if nil ~= TAccLogin then
            TAccLogin.SetAccList(zList);
        else
            TGPLog.LogE("LoginV", "Set saved list, quick login module is null.");
        end;
    end;

    -- 邮箱历史账号
    SetMailSavedList = function (zList)
        if nil ~= TMailAccLogin then
            TMailAccLogin.SetAccList(zList);
        else
            TGPLog.LogE("LoginV", "Set mail saved list, mail login module is null.");
        end;
    end;

    -- 回退上一个页面
    GoBackPage = function()
        local zParam = {};
        if TLoginView.nLstPage == -1 then
            if base_utility.CLIENT_TYPE.OVERSEA_VER ==  base_utility.get_client_version_type() then
                TLoginView.nLstPage = ELoginPage.lpMailAccLogin;
            else
                TLoginView.nLstPage = ELoginPage.lpAccLogin;
            end
        end;
        zParam["nPageIdx"] = TLoginView.nLstPage;
        local result = comm_center.call_service("Svr_SwitchLoginPage", zParam);
        if true == result then
            TLoginView.nLstPage = -1;
            return true;
        else
            TGPLog.LogE("LoginV", "Goback to page fail:" .. tostring(TLoginView.nLstPage));
            return false;
        end;
    end;

    -- 获取最后一次切换的页面
    GetLastPage = function()
        return TLoginView.nLstPage;
    end;

    -- 加载对应页面
    SwitchPage = function(nPageIdx)
        if (nPageIdx == TLoginView.nCurPage) then
            TGPLog.LogI("LoginV", "Switch to same page:" .. tostring(nPageIdx))
            return true;
        end;
        
        if (nil == TLoginView.pObjMain) then
            TGPLog.LogE("LoginV", "User object not created.");
            return false;
        end;

        if (nPageIdx >= ELoginPage.lpMinPage) and (nPageIdx < ELoginPage.lpMaxPage) then
            local   sPageXML = TLoginView.zPageMap[nPageIdx];

            if (nil == sPageXML) then
                TGPLog.LogE("LoginV", "Get page XML fail:"..tostring(nPageIdx));
                return false;
            end;

            if TLoginView.nCurPage >= ELoginPage.lpMinPage and 
               TLoginView.nCurPage <  ELoginPage.lpMaxPage then
                local   sOldXML = TLoginView.zPageMap[TLoginView.nCurPage];

                --TGPLog.LogI("LoginV", "sPageXML = "..sPageXML);
                --TGPLog.LogI("LoginV", "sOldXML = "..sOldXML);
                TLoginView.UnInitPage(TLoginView.nCurPage);
                -- 相同的页面，不切换
                if sOldXML == sPageXML then
                    TGPLog.LogE("LoginV", "the same page..");
                    TLoginView.nCurPage = nPageIdx;
                    TLoginView.InitPage(nPageIdx);
                    return true;
                end;
            end;

            TLoginView.pObjMain:UnLoadContent();

            ui_utility.setproperty_by_id(TLoginView.pObjMain:GetControlID(), 
                                         "Content", sPageXML);
            if (TRUE == TLoginView.pObjMain:LoadContent()) then
                TGPLog.LogI("LoginV", "LoadContent succeed");
                TLoginView.UpdateMainPage(nPageIdx);
                TLoginView.nCurPage = nPageIdx;
                TLoginView.InitPage(nPageIdx);
                return true;
            else
                TGPLog.LogE("LoginV", "LoadContent failed");
                return false;
            end;
        else
            TGPLog.LogE("LoginV", "Page index out of range:"..tostring(nPageIdx));
            return false;
        end;
    end;

    -- 获取当前页面
    IsSamePage = function(nPageIdx)
        return (TLoginView.nCurPage == nPageIdx);
    end;

    -- 指定页面是否是上一个页面
    IsLastPage = function(nPageIdx)
        return (TLoginView.nLstPage == nPageIdx);
    end;

    -- 初始化页面
    InitPage = function(nPage)
        if nil == TLoginView.pObjMain then
            TGPLog.LogE("Loading", "Initialize page, user object is null.");
            return;
        end;

        local   nViewID = TLoginView.pObjMain:GetControlID();

        if     (ELoginPage.lpQKLogin  == nPage) then    -- 快速登录
            TQuickLogin.InitView(nViewID);
            TQuickLogin.ShowView();
        elseif (ELoginPage.lpAccLogin == nPage) then    -- 帐号登录
            TAccLogin.InitView(nViewID);
            TAccLogin.ShowView();
        elseif (ELoginPage.lpQRLogin  == nPage) then    -- 二维码登录
            TQRLogin.InitView(nViewID);
            TQRLogin.ShowView();
        elseif (ELoginPage.lpSecCheck == nPage) then    -- 安全检测界面
            TLoadingView.InitView(nViewID);
            TLoadingView.ShowView(false);
        elseif (ELoginPage.lpLogining == nPage) then    -- 登录中&安全检测页面
            TLoadingView.InitView(nViewID);
            TLoadingView.ShowView(true);
        elseif (ELoginPage.lpLoginErr == nPage) then    -- 登录错误页面
            TLoginError.InitView(nViewID);
            TLoginError.ShowView();
        elseif (ELoginPage.lpUpdating == nPage) then    -- 升级界面
            TLoginUpdate.InitView(nViewID);
            TLoginUpdate.ShowView();
            TNavTabView.ShowView(false);
            comm_center.call_service("Svr_ShowSettingsButton", { show = 0 });
        elseif (ELoginPage.lpPictChk  == nPage) then    -- 验证码
            TPictCheck.InitView(nViewID);
            TPictCheck.ShowView();
        elseif (ELoginPage.lpWeChatQRLogin == nPage) then   -- 微信二维码
            TWeChatQRLogin.InitView(nViewID);
            TWeChatQRLogin.ShowView();
        elseif (ELoginPage.lpOverseasLogin == nPage) then   -- 国际版登陆
            TOverseaLogin.InitView(nViewID);
            TOverseaLogin.ShowView();
        elseif (ELoginPage.lpMailAccLogin == nPage) then -- 邮箱登录
            TMailAccLogin.InitView(nViewID);
            TMailAccLogin.ShowView();
        elseif (ELoginPage.lpProxyPref == nPage) then   -- 代理设置
            TProxyPrefView.InitView(nViewID);
            TProxyPrefView.ShowView();
        else
            TGPLog.LogE("LoginV", "Initialize page, index error:" .. 
                        tostring(nPage));
        end;
    end;

    -- 卸载页面
    UnInitPage = function(nPage)
        if     (ELoginPage.lpQKLogin  == nPage) then    -- 快速登录
            TQuickLogin.HideView();
            TQuickLogin.UnInitView();
        elseif (ELoginPage.lpAccLogin == nPage) then    -- 帐号登录
            TAccLogin.HideView();
            TAccLogin.UnInitView();
        elseif (ELoginPage.lpQRLogin  == nPage) then    -- 二维码登录
            TQRLogin.HideView();
            TQRLogin.UnInitView();
        elseif (ELoginPage.lpSecCheck == nPage) then    -- 安全检测界面
            TLoadingView.HideView();
            TLoadingView.UnInitView();
        elseif (ELoginPage.lpLogining == nPage) then    -- 登录中&安全检测页面
            TLoadingView.HideView();
            TLoadingView.UnInitView();          
        elseif (ELoginPage.lpLoginErr == nPage) then    -- 登录错误页面
            TLoginError.HideView();
            TLoginError.UnInitView();           
        elseif (ELoginPage.lpUpdating == nPage) then    -- 升级界面
            TLoginUpdate.HideView();
            TLoginUpdate.UnInitView();
        elseif (ELoginPage.lpPictChk  == nPage) then    -- 验证码
            TPictCheck.HideView();
            TPictCheck.UnInitView();
        elseif (ELoginPage.lpWeChatQRLogin == nPage) then   -- 微信二维码
            TWeChatQRLogin.HideView();
            TWeChatQRLogin.UnInitView();
        elseif (ELoginPage.lpOverseasLogin == nPage) then   -- 国际版登陆
            TOverseaLogin.HideView();
            TOverseaLogin.UnInitView();
        elseif (ELoginPage.lpMailAccLogin == nPage) then -- 邮箱登录
            TMailAccLogin.HideView();
            TMailAccLogin.UnInitView();
        elseif (ELoginPage.lpProxyPref == nPage) then   -- 代理设置
            TProxyPrefView.HideView();
            TProxyPrefView.UnInitView();
        else
            TGPLog.LogE("LoginV", "UnInitialize page, index error:" .. 
                        tostring(nPage));
            return;
        end;
        TGPLog.LogE("LoginV", "UnInitialize page, index:" .. tostring(nPage));
        if ELoginPage.lpSecCheck ~= nPage and 
           ELoginPage.lpLogining ~= nPage and
           ELoginPage.lpLoginErr ~= nPage and
           ELoginPage.lpPictChk  ~= nPage then
            TLoginView.nLstPage = TLoginView.nCurPage;
        end;

        TLoginView.nCurPage = -1;
    end;

    -- 修正MainPage, launcher启动样式不同
    UpdateMainPage = function (nPage)
        local ELauncherPage = {
           { page = ELoginPage.lpQKLogin; loginUIName = EQKLoginUI.sQuickLogin },
           { page = ELoginPage.lpAccLogin; loginUIName = EAccLoginUI.sAccPanel },
           { page = ELoginPage.lpWeChatQRLogin; loginUIName = EWeChatQRView.sQRPanel },
           { page = ELoginPage.lpOverseasLogin; loginUIName = EOverseaLoginUI.sOverseaLogin },
           { page = ELoginPage.lpMailAccLogin; loginUIName = EMailAccLoginUI.sAccPanel }, 
        };
        local launcherPage = nil;
        for index, item in ipairs(ELauncherPage) do
            if nPage == item.page then
                launcherPage = item;
                break;
            end 
        end
        TGPLog.LogI("LoginV", "UpdateMainPage, current page: " .. tostring(nPage));
        if launcherPage ~= nil then
            TGPLog.LogI("LoginV", "UpdateMainPage, isLauncher: " .. tostring(TLoginCtrl.bIsLauncher));
            if TLoginCtrl.bIsLauncher then
                if TLoginCtrl.zLaunchCmdInfo ~= nil and TLoginCtrl.zLaunchCmdInfo.game_path ~= nil and TLoginCtrl.zLaunchCmdInfo.game_path ~= "" then
                    TGPLog.LogI("LoginV", "UpdateMainPage, game_path: " .. TLoginCtrl.zLaunchCmdInfo.game_path);
                    local icon_path = TLoginCtrl.zLaunchCmdInfo.game_path .. "\\WeGameLauncher\\game\\login_logo.png";
                    if base_utility.is_file_exist(icon_path) then
                        local loginUIName = launcherPage.loginUIName;
                        if loginUIName ~= nil and loginUIName ~= "" then 
                            local icon_background = "ONEIMAGE:" .. icon_path ..  ";Center;0;";
                            local loginUI = ui_utility.get_ctrl_id_by_path(TLoginView.pObjMain:GetControlID(), loginUIName);
                            local WegameLogo = ui_utility.get_ctrl_id_by_path(loginUI,"lblLogo");
                            local launcherLogo = ui_utility.get_ctrl_id_by_path(loginUI,"lblLauncherLogo");
                            ui_utility.setproperty_by_id(launcherLogo, "Background", icon_background);    
                            ui_utility.setproperty_by_id(WegameLogo, "Visible", "false");
                            ui_utility.setproperty_by_id(launcherLogo, "Visible", "true");
                            TGPLog.LogI("LoginV", "UpdateMainPage, find icon, path: " .. icon_path, ", loginUIName: " .. tostring(loginUIName));
                        else
                            TGPLog.LogE("LoginV", "UpdateMainPage, loginUIName is nil: " .. tostring(loginUIName));
                        end
                    else
                        TGPLog.LogE("LoginV", "UpdateMainPage, fail to find icon, path: " .. icon_path);
                    end
                else
                    TGPLog.LogE("LoginV", "UpdateMainPage, game_path not exists.");
                end
            end
        end
    end;

    -- 显示帐号保护检测界面
    ShowPwdGuardChk = function(sJson)
    end;

    -- 显示服务器登录失败提示
    ShowSvrErrTips = function()
        local nMainID = ui_utility.get_ctrl_id_by_cid(CID_MAINFRAME_Dialog_MainFrame);

        local zParam = 
        {
            position = "center",
            title = LoadStr("STR_LOGIN_HINT"),
            width = 480,
            height = 230,
            titleIcon = "",
            icon = "",
            tipsIcon = poptips_icons.kError,
            descTitle = "",
            desc = LoadStr("STR_LOGIN_SVR_ERROR_TIPS"),
            parent_id = main_id,
            modal = false,
            always_center = true,
            okBtn = 
            {
                visible = "true",
                text = LoadStr("STR_LOGIN_CONFIRM"),
                close_win = true,
                handle = function()
                end
            },
            cancelBtn = 
            {
                visible = "false",
                text = LoadStr("STR_LOGIN_CANCEL"),
                handle = function()
                end
            }
       };

       poptips_control.show_tips(zParam);
    end;

    -- ID是否有效
    IsInvalid = function(dwTemp)
        return (nil ~= dwTemp) and (0 ~= dwTemp);
    end;

    -- 最小化
    OnClkMin = function(pUILib, nBtnID)
        if (nil ~= TLoginView.pDlgLogin) then
            TLoginView.pDlgLogin:Minimize();
        else
            TGPLog.LogE("LoginV", "Click min button, dialog is null.");
        end;
    end;

    -- 关闭
    OnClkCls = function(pUILib, nBtnID)
        comm_center.call_service("Svr_ExitWeGame", {report=1}); -- 退出
    end;

    -- 显示QR按钮
    ShowQRButton = function(bShow, bAni)
        if ELoginPage.lpQKLogin == TLoginView.nCurPage then
            -- 快速登录不显示该按钮
            TQuickLogin.ShowQRButton(false, bAni);
        elseif ELoginPage.lpAccLogin == TLoginView.nCurPage then
            TAccLogin.ShowQRButton(bShow, bAni);
        else
            TGPLog.LogI("LoginV", "Show QR button, not login page:" ..
                        tostring(TLoginView.nCurPage));
        end;
    end;

    -- 设置状态
    SetStatus = function(zStatus)
        if  (ELoginPage.lpQKLogin  == TLoginView.nCurPage) then -- 快速登录
            TQuickLogin.SetStatus(zStatus);
        elseif (ELoginPage.lpAccLogin == TLoginView.nCurPage) then  -- 帐号登录
            TAccLogin.SetStatus(zStatus);
        elseif (ELoginPage.lpQRLogin  == TLoginView.nCurPage) then  -- 二维码登录
            TQRLogin.SetStatus(zStatus);
        elseif (ELoginPage.lpSecCheck == TLoginView.nCurPage) then  -- 安全检测界面
            TLoadingView.SetStatus(zStatus);
        elseif (ELoginPage.lpLogining == TLoginView.nCurPage) then  -- 登录中&安全检测页面
            TLoadingView.SetStatus(zStatus);
        elseif (ELoginPage.lpLoginErr == TLoginView.nCurPage) then  -- 登录错误页面
            TLoginError.SetStatus(zStatus);
        elseif (ELoginPage.lpUpdating == TLoginView.nCurPage) then  -- 升级界面
            TLoginUpdate.SetStatus(zStatus);
        elseif (ELoginPage.lpPictChk  == TLoginView.nCurPage) then  -- 验证码
            TPictCheck.SetStatus(zStatus);
        elseif (ELoginPage.lpWeChatQRLogin == TLoginView.nCurPage) then   --微信二维码
            TWeChatQRLogin.SetStatus(zStatus);
        elseif (ELoginPage.lpOverseasLogin == TLoginView.nCurPage) then   --国际版登陆
            TOverseaLogin.SetStatus(zStatus);
        elseif (ELoginPage.lpMailAccLogin == TLoginView.nCurPage) then -- 邮箱登录
            TMailAccLogin.SetStatus(zStatus);
        else
            TGPLog.LogI("LoginV", "Initialize page, index error:" .. tostring(TLoginView.nCurPage));
        end;
    end;

    -- 获取窗口位置
    OnGetWndRect = function(zParam)
        if nil ~= TLoginView.pDlgLogin then
            local   rtTemp = nil;
            local   rtWnd  = {};

            if (true == zParam["screen"]) then
                rtTemp = TLoginView.pDlgLogin:GetRectEx(TRUE,TRUE);
            else
                rtTemp = TLoginView.pDlgLogin:GetRectEx(FALSE,TRUE);
            end;

            rtWnd["left"  ] = rtTemp.left;
            rtWnd["top"   ] = rtTemp.top;
            rtWnd["right" ] = rtTemp.right;
            rtWnd["bottom"] = rtTemp.bottom;

            zParam["rect"] = rtWnd;
        else
            TGPLog.LogI("LoginV", "Svr_GetLoginRect, window not created.");
        end;

        return zParam;
    end;

    -- 获取登录窗体
    OnGetLoginWnd = function(zParam)
        if nil ~= TLoginView.pDlgLogin then
            zParam["window"] = TLoginView.pDlgLogin:GetControlID();
        else
            TGPLog.LogI("LoginV", "Svr_GetLoginWnd, window not created.");
        end;

        return zParam;
    end;

    -- QR处理逻辑
    ShowQRImage = function()
        if nil ~= TQRLogin then
            TQRLogin.ShowQRImage();
        else
            TGPLog.LogE("LoginV", "Show QR image, QRView is null.");
        end;
    end;

    ShowQRConfirm = function()
        if nil ~= TQRLogin then
            TQRLogin.ShowQRConfirm();
        else
            TGPLog.LogE("LoginV", "Show QR image, QRView is null.");
        end;        
    end;

    ShowQRTimeOut = function()
        if nil ~= TQRLogin then
            TQRLogin.ShowQRTimeOut();
        else
            TGPLog.LogE("LoginV", "Show QR image, QRView is null.");
        end;
    end;

    ShowQRFailed = function()
        if nil ~= TQRLogin then
            TQRLogin.ShowQRFailed();
        else
            TGPLog.LogE("LoginV", "Show QR image, QRView is null.");
        end;
    end;

    ShowRQChecking = function()
        if nil ~= TQRLogin then
            TQRLogin.ShowRQChecking();
        else
            TGPLog.LogE("LoginV", "Show QR image, QRView is null.");
        end;        
    end;

    -- wechat QR处理逻辑
    ShowWeChatQRImage = function()
        if nil ~= TWeChatQRLogin then
            TWeChatQRLogin.ShowQRImage();
        else
            TGPLog.LogE("LoginV", "Show WeChat QR image, QRView is null.");
        end;
    end;

    ShowWeChatQRGetFail = function()
        if nil ~= TWeChatQRLogin then
            TWeChatQRLogin.ShowGetQRFail();
        else
            TGPLog.LogE("LoginV", "ShowWeChatQRGetFail, QRView is null.");
        end;

    end;

    ShowWeChatQRTimeOut = function()
        if nil ~= TWeChatQRLogin then
            TWeChatQRLogin.ShowQRTimeOut();
        else
            TGPLog.LogE("LoginV", "Show QR image, QRView is null.");
        end;
    end;

    ShowWeChatQRScaned = function()
        if nil ~= TWeChatQRLogin then
            TWeChatQRLogin.ShowQRScanedWaitingConfirm();
        else
            TGPLog.LogE("LoginV", "Show QR image, QRView is null.");
        end;
    end;

    ShowWGTips = function(bShow)
        if nil ~= TLoginView.pWGADTips then
            if bShow then
                TLoginView.pWGADTips:Show(TRUE);
            else
                TLoginView.pWGADTips:Show(FALSE);
            end;
        else
            TGPLog.LogE("LoginV", "Show launch tips, control is null.");
        end;
    end;

    -- 显示黑机器tip提示
    ShowTasBMTips = function(bShow, sTips)
        if TQRLogin ~= nil then
            TQRLogin.ShowQRBMTips(bShow, sTips);
        end
    end;

    -- 显示TAS安全提示
    ShowTASTips = function()
        popup_wnd_control.show_tas_scandangers_tip(CID_LOGIN_DLG);

        -- 隐藏安全登录输入框
        if TLoginView.IsSamePage(ELoginPage.lpAccLogin) then
            TAccLogin.ShowTEdit(false);
        end;

        if TLoginView.IsSamePage(ELoginPage.lpMailAccLogin) then
            TMailAccLogin.ShowTEdit(false);
        end
    end;

    -- 点击了静音按钮
    OnClkMute = function(pUILib, nBtnID)
        if TLoginView.bIsMute then
            TLoginView.SetWebMute(false);
        else
            TLoginView.SetWebMute(true);
        end;
    end;

    OnClkSetting = function()
        local zParam = {};
        zParam["nPageIdx"] = ELoginPage.lpProxyPref;
        comm_center.call_service("Svr_SwitchLoginPage", zParam);
    end;

    OnClkMore = function ()
        comm_center.call_service("i_service_open_link", TLoginView.curImageAdLink);
        TLoginView.ReportLoginAd(TLoginModule.GetLoginAD(), "click");
    end;

    SetWebMute = function(bMute)
        local   zParam = {};

        if bMute then
            zParam["mute"] = 1;
        else
            zParam["mute"] = 0;
        end;

        comm_center.send_broadcast("Msg_SetWebMute", zParam);

        TLoginView.bIsMute = bMute;
        TLoginView.ChangeMuteBG();
    end;

    -- 修改浏览器静音按钮背景
    ChangeMuteBG = function()
        if nil ~= TLoginView.pBtnMute then
            local   nBtnID = TLoginView.pBtnMute:GetControlID();

            if TLoginView.bIsMute then
                ui_utility.setproperty_by_id(nBtnID, "Background", ELoginRes.sMuteNrl);
                ui_utility.setproperty_by_id(nBtnID, "BackgroundHover", ELoginRes.sMuteHov);
                ui_utility.setproperty_by_id(nBtnID, "BackgroundPressed", ELoginRes.sMuteClk);
                --ui_utility.setproperty_by_id(nBtnID, "Tip", "取消静音");
                ui_utility.setproperty_by_id(nBtnID, "Tip_LID", "10678");
            else
                ui_utility.setproperty_by_id(nBtnID, "Background", ELoginRes.sSoundNrl);
                ui_utility.setproperty_by_id(nBtnID, "BackgroundHover", ELoginRes.sSoundHov);
                ui_utility.setproperty_by_id(nBtnID, "BackgroundPressed", ELoginRes.sSoundClk);
                -- ui_utility.setproperty_by_id(nBtnID, "Tip", "静音");
                ui_utility.setproperty_by_id(nBtnID, "Tip_LID", "10677");
            end;
        end;
    end;

    OnSvrShowTips = function(zParam)
        if nil ~= TLoginView.pBtnTips then
            local   sTips = zParam["text"];

            if nil ~= sTips then
                local   sTemp = U8toCUIStr(sTips);
                TLoginView.pBtnTips:SetCaption(sTemp);
            end;

            local rtTemp  = TLoginView.pBtnTips:GetRectEx(FALSE,TRUE);
            local nWidth  = rtTemp.right - rtTemp.left;
            local nHeight = rtTemp.bottom - rtTemp.top;

            rtTemp.left   = zParam["left"];
            rtTemp.top    = zParam["top"];
            rtTemp.right  = rtTemp.left + nWidth;
            rtTemp.bottom = rtTemp.top + nHeight;

            TLoginView.pBtnTips:MoveEx(rtTemp,TRUE);
            TLoginView.pBtnTips:Show(TRUE);
        end;
    end;
    
    OnSvrHideTips = function(zParam)
        if nil ~= TLoginView.pBtnTips then
            TLoginView.pBtnTips:Show(FALSE);
        end;
    end;

    -- 显示静音按钮
    OnSvrShowMute = function(zParam)
        if nil ~= TLoginView.pBtnMute then
            local   bMute = false;

            if (nil ~= zParam["mute"]) and (0 ~= zParam["mute"]) then
                bMute = true;
            else
                bMute = false;
            end;

            if bMute ~= TLoginView.bIsMute then
                TLoginView.bIsMute = bMute;
                TLoginView.ChangeMuteBG();
            end;

            local show_mute_btn = false;

            if (nil ~= zParam["show"]) and (1 == zParam["show"]) then
                TLoginView.pBtnMute:Show(TRUE);
                show_mute_btn = true;
            else
                TLoginView.pBtnMute:Show(FALSE);
            end;

            if show_mute_btn then
                local is_setting_btn_visible = false;
                local btn_ww = 0;
                if nil ~= TLoginView.pBtnSetting then
                    local visible = TLoginView.pBtnSetting:IsVisible();
                    if TRUE == visible then
                        is_setting_btn_visible = true;
                        local rect = TLoginView.pBtnSetting:GetRect();
                        btn_ww = rect.right - rect.left;
                    end
                end
                if is_setting_btn_visible then
                    local ww, wh = ui_utility.get_control_size_by_id(TLoginView.pBtnMuteID);
                    ww = ww + btn_ww + 6;
                    ui_utility.setproperty_by_id(TLoginView.pBtnMutePanelID, "Width", tostring(ww));
                end
            end

        end;
    end;

    OnSvrShowSettings = function(zParam)
        if nil ~= TLoginView.pBtnSetting then
            if (nil ~= zParam["show"]) and (1 == zParam["show"]) then
                TLoginView.pBtnSetting:Show(TRUE);
            else
                TLoginView.pBtnSetting:Show(FALSE);
            end;
        end;
    end;

    -- 页面静音
    OnMsgWebMute = function(zParam)
        if nil == zParam then
            TGPLog.LogE("LoginV", "Mute change, paramter is nil.");
            return;
        end;

        if nil ~= TLoginView.pBtnMute then
            local   bMute = false;

            if 1 == zParam["mute"] then
                bMute = true;
            end;

            if bMute == TLoginView.bIsMute then
                TGPLog.LogI("LoginV", "Set mute, same state.");
                return;
            end;

            TLoginView.bIsMute = bMute;
            TLoginView.ChangeMuteBG();
        else
            TGPLog.LogE("LoginV", "On MsgWegMute, mute button is nil.");
        end;
    end;

    -- 登录广告更新
    UpdateLoginAD = function(zParam)
        if nil == zParam then
            return;
        end

        if "1" == zParam.ad_type and "" == zParam.ad_video_url then
            -- 图片类型而且没有小视频则直接native加载图片
            if nil ~= TLoginView.pPnlBack then
                local  sIcon = zParam.ad_tpl_url;
                local  defaultIcon = "client_login\\default_bg.png";
                if (nil ~= string.find(sIcon, "http:") or nil ~= string.find(sIcon, "https:")) then
                    sIcon = "ONEIMAGE:" .. defaultIcon .. "|" .. sIcon;
                elseif ("" == sIcon) then
                    sIcon = "ONEIMAGE:" .. defaultIcon;
                else
                    sIcon = "ONEIMAGE:" .. sIcon;
                end;
                TGPLog.LogE("LoginV", "Update login AD, image_path:" .. sIcon);
                ui_utility.setproperty_by_id(
                    TLoginView.pPnlBack:GetControlID(), "Background", sIcon);
                TLoginView.ReportLoginAd(zParam, "show");
            end

            if "" ~= zParam.click_btn_show_txt and "" ~= zParam.ad_link_url then
                if nil ~= TLoginView.pBtnMore then
                    ui_utility.setproperty_by_id(TLoginView.pBtnMore:GetControlID(), "Visible", 
                        "true");
                    ui_utility.setproperty_by_id(TLoginView.pBtnMore:GetControlID(), "Caption",
                        zParam.click_btn_show_txt);
                end

                -- test
                -- zParam.ad_link_url = "http://test.gg.wegame.oa.com/portal/index.html#/ad/index";
                TLoginView.curImageAdLink = base_utility.json_to_table(zParam.ad_link_url);
                if nil == TLoginView.curImageAdLink then
                    TLoginView.curImageAdLink = {};
                    TLoginView.curImageAdLink.type = "open_web";
                    TLoginView.curImageAdLink.browser = "multi_web";
                    TLoginView.curImageAdLink.url = zParam.ad_link_url;
                    TLoginView.curImageAdLink.from = "login";
                    TLoginView.curImageAdLink.use_ptlogin = "0";
                end
            else
                if nil ~= TLoginView.pBtnMore then
                    ui_utility.setproperty_by_id(TLoginView.pBtnMore:GetControlID(), "Visible", 
                        "false");
                end
            end
        else
            if nil ~= TLoginView.pBtnMore then
                ui_utility.setproperty_by_id(TLoginView.pBtnMore:GetControlID(), "Visible", 
                    "false");
            end

            TLoginView.LoadWebComponent();
            if nil == TLoginView.pWebBack then
                TGPLog.LogE("LoginV", "Update login AD, web browser is null.");
                return;
            end;

            local   nTempID = TLoginView.pWebBack:GetControlID();
            ui_utility.setproperty_by_id(nTempID, "OnNavigateFailed", "TLoginView.OnNavigateFail");
            ui_utility.setproperty_by_id(nTempID, "OnNavigateComplete", "TLoginView.OnNavigateOK");
            ui_utility.setproperty_by_id(nTempID, "OnCrash","TLoginView.OnWebCrash");

            if nil ~= zParam and nil ~= zParam.game_id and nil ~= zParam.ad_type then
                local work_path = base_utility.get_work_path();
                local base_url = LoadStr("LOGIN_AD_URL");
                TGPLog.LogI("LoginV", "Update login AD:" .. base_utility.table_to_json(zParam));
            
                local   sTemp = U8toCUIStr(base_url);
            
                TLoginView.pWebBack:Navigate(sTemp);

                -- 在导航完成的时候再显示出来
                --TLoginView.pWebBack:Show(false);
            else
                TGPLog.LogI("LoginC", "Login AD updated, param is error");
            end;
        end
    end;

    OnNavigateFail = function()
        TGPLog.LogI("LoginV", "Web navigate failed.");

        if nil ~= TLoginView.pWebBack then
            TLoginView.pWebBack:Show(0);
        end;
    end;

    OnNavigateOK = function()
        TGPLog.LogE("LoginV", "Web navigate success.");
        -- 登录广告显示时机改为页面调用ShowLoginAd
        --[[
        if nil ~= TLoginView.pWebBack then
            TLoginView.pWebBack:Show(1);
        end;
        ]]
    end;

    ShowLoginAd = function()
        if nil ~= TLoginView.pWebBack then
            TLoginView.pWebBack:Show(1);
        end;
    end;

    LoadWebComponent = function()
        local dwLogin = ui_utility.get_ctrl_id_by_cid(CID_LOGIN_DLG);
        local web_component_ptr = ui_utility.get_ctrl_ptr_by_path(dwLogin, "pnlBack\\Ctn_WebArea");
        if web_component_ptr ~= nil then
            local is_load = web_component_ptr:IsLoad();
            if is_load ~= TRUE then
                local result = web_component_ptr:LoadContent();
                if result ~= TRUE then
                    
                    TGPLog.LogE("LoginV", "load Web Component failed.");
                end
            end
            TLoginView.pWebBack = ui_utility.get_ctrl_ptr_by_path(dwLogin, ELoginUI.sWebBack);
        end
    end;

    UnloadWebComponent = function()
        local dwLogin = ui_utility.get_ctrl_id_by_cid(CID_LOGIN_DLG);
        local web_component_ptr = 
            ui_utility.get_ctrl_ptr_by_path(dwLogin, "pnlBack\\Ctn_WebArea");
        if web_component_ptr ~= nil then
            web_component_ptr:UnLoadContent();
        end
        TGPLog.LogE("LoginV", "unload_web_component.");
    end;

    ShowNavTab = function(param)
        if nil == param then
            param = {};
        end

        local show = FALSE;
        if true == param.show then
            show = TRUE;
        end
        if true == TLoginView.could_show_navtab and nil ~= TLoginView.pNavTab then
            TGPLog.LogE("LoginV", "ShowNavTab.");
            TLoginView.pNavTab:Show(show);
        end;
    end;

    OnWebCrash = function()
        TGPLog.LogI("LoginV", "Web crashed.");

        if nil ~= TLoginView.pWebBack then
            TLoginView.pWebBack:Show(0);
            TLoginView.UnloadWebComponent();
        end;
    end;

    -- 关闭
    OnClose = function(pUILib, dwDlgID, bClose)
        TLoginView.OnClkCls(pUILib, dwDlgID);
    end;

    -- 显示web二维码
    ShowWebPict = function (url)
        if nil == TLoginView.pDlgLogin then
             return;
        end
        TNewPictCheck.InitView(TLoginView.pDlgLogin:GetControlID());
        TNewPictCheck.ShowView(url);
    end;

    UnInitWebPict = function ()
        TNewPictCheck.UnInitView();
    end;

    ShowDPITips = function ()
        local cancel_txt = LoadStr("DPI_TIPS_YES");
        local ok_txt = LoadStr("DPI_TIPS_NO");
        local data = {};
        local tipParam =
        {
            native = true,
            position = "center",
            title = LoadStr("ID_TPF_TIPS"),
            width = 450,
            height = 230,
            titleIcon = "",
            icon = "",
            tipsIcon = "",
            descTitle = LoadStr("DPI_TIPS"),
            desc = LoadStr("DPI_TIPS_DESC"),
            okBtn = 
            {
                visible = "true",
                text = ok_txt,
                handle = function()
                        data["mode"] = 0;
                        comm_center.call_service("Svr_SetDPIAwareMode", data);
                        poptips_control.close_tips();
                        if is_busy == true then
                                comm_center.call_service("Svr_KillInstallProc", {});
                            local gamelib =
                                base_utility.get_component_adapter("IGame_library",
                                "ierd_tgp.game_library.Get_game_library_adapter();");
                            gamelib:KillAllAppStoreGames();
                        end;
                        comm_center.call_service("i_svr_save_main_wnd_pos", {});
                        comm_center.call_service("Svr_RestartWG", {});
                end
            },
            cancelBtn = 
            {
                visible = "true",
                text = cancel_txt,
                handle = function()
                    TLoginCtrl.ShowLogin();
                end
            }
        }
        bRet = true;
        poptips_control.show_tips(tipParam);
        local dpi_tips_info = {
            common = 1, key = "wegame_login.dpi_tips_info",
            value = 1};
        comm_center.call_service("Svr_SetConfig", dpi_tips_info);
    end;
    
    SetCouldShowNavTab = function(could_show) 
        TLoginView.could_show_navtab = could_show;
    end;

    ReportLoginAd = function(ad_info, action)
        if ad_info == nil then
            TGPLog.LogE("LoginV", "ReportLoginAd, ad info is nil");
            return;
        end;
        local report_info = {};
        report_info.ad_type=ad_info.ad_type;
        report_info.ad_id=ad_info.ad_id;
        report_info.task_id=ad_info.task_id;
        report_info.game_id=ad_info.game_id;
        if (nil ~= string.find(ad_info.ad_tpl_url, "http:") or 
            nil ~= string.find(ad_info.ad_tpl_url, "https:")) then
            report_info.tpl_url_type = 1;
        else
            report_info.tpl_url_type = 0;
        end;
        if ad_info.ad_video_url ~= nil and ad_info.ad_video_url ~= "" then
            if (nil ~= string.find(ad_info.ad_video_url, "http:") or 
                nil ~= string.find(ad_info.ad_video_url, "https:")) then
                report_info.video_url_type = 1;
            else
                report_info.video_url_type = 0;
            end;
            report_info.has_video = 1;
        else
            report_info.has_video = 0;
        end;
        if action ~= nil and action == "click" then
            report_info.click_position = 1;
        end;
        comm_center.call_service("Service_ReportLoginAdState", 
            {sub_action=action, kv_info=base_utility.table_to_json(report_info)});
        TGPLog.LogE("LoginV", "ReportLoginAd.");
    end;

    HidePickCheckView = function()
        TGPLog.LogE("LoginV", "HidePickCheckView.");
        TLoginView.UnInitWebPict();
    end;

    HideLoginView = function()
         TLoginView.hide_by_login_protocal = true;

        if nil ~= TLoginView.pDlgLogin then
            TLoginView.pDlgLogin:Show(FALSE);
        end;
    end;
    
    ShowLoginView = function()
        if nil ~= TLoginView.pDlgLogin then
            TLoginView.pDlgLogin:Show(TRUE);
        end;
        TLoginView.hide_by_login_protocal = false;
    end;
    
    ShowCapsTips = function(bshow)
        if TAccLogin ~= nil then
            TAccLogin.ShowCapsTips(bshow);
        end;

        if TMailAccLogin ~= nil then
            TMailAccLogin.ShowCapsTips(bshow);
        end;
    end;

    -- 登录对话框
    pPnlClient= nil;
    root_id = nil;   -- 登录对话框ID 

    pBtnTips  = nil;

    pDlgLogin = nil;
    pObjMain  = nil;
    pWGADTips = nil;

    pBtnMute  = nil;        -- 静音按钮
    pBtnCls   = nil;        -- 关闭按钮
    pBtnMin   = nil;        -- 最小化按钮

    -- 背景信息
    pPnlBack  = nil;        -- 背景
    pWebBack  = nil;        -- 浏览器
    bIsMute   = false;      -- 是否静音
    pBtnMore  = nil;

    -- 界面映射表
    zPageMap  = {};         -- ELoginPage <--> PageXML
    nCurPage  = -1;         -- 当前显示的页面索引
    nLstPage  = -1;         -- 最后一个页面
    curImageAdLink = {};

    could_show_navtab = true;
    hide_by_login_protocal = false;
};